package cn.wolfcode.crmspringboot.web.controller;



import cn.wolfcode.crmspringboot.domain.Employee;
import cn.wolfcode.crmspringboot.domain.Notice;
import cn.wolfcode.crmspringboot.query.QueryObject;
import cn.wolfcode.crmspringboot.service.INoticeService;
import cn.wolfcode.crmspringboot.util.JsonResult;
import cn.wolfcode.crmspringboot.util.UserContext;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    private INoticeService noticeService;


//    @RequestMapping("/list")
//    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
//        Employee employee = UserContext.getCurrentUser();
//        PageInfo<Notice> pageInfo = noticeService.query(qo,employee.getId());
//        model.addAttribute("result", pageInfo);
//        return "notice/list";
//    }

    @RequestMapping("/delete")
    @ResponseBody
    public JsonResult delete(Long id){
        if (id != null) {
            noticeService.delete(id);
        }
        return new JsonResult();
    }


    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(Notice notice){
        if (notice.getId() != null) {
            noticeService.update(notice);
        }else {
            noticeService.save(notice);
        }
        return new JsonResult();
    }

//    @RequestMapping("/show")
//    public String show(Model md,Long id){
//        Employee employee = UserContext.getCurrentUser();
//        noticeService.insert(id,employee.getId());
//        Notice notice = noticeService.get(id);
//        md.addAttribute("notice", notice);
//
//        return "notice/show";
//    }
}
